cc.Class({
    extends: cc.Component,
    properties: {
        type: 0,
        state: 0,
        index: -1,
    },

    onLoad: function () {
        this.init();
    },
    ///由GameView调用控制  初始化角色数据默认值
    init: function () {
        this.node.on(cc.Node.EventType.TOUCH_END, this.touchEndFunc.bind(this));
    },
    update: function (dt) {
    },

    changeAppearance: function () {
        this.node.setScale(window.GameConstant.GameDefaultValue.SCALE_MID);
    },
    resetAppearance: function () {
        this.node.setScale(window.GameConstant.GameDefaultValue.SCALE_MAX);
    },
    touchEndFunc: function () {
        if (this.index < 0) {
            console.log("index < 0");
            return;
        }
        if (!this.checkMoveable()) {
            console.log("calced, find not move");
            return
        }

        var preManIndex = window.CardViewData.manLand.index;
        window.CardViewData.manLand.index = this.index;

        var tmpNode = cc.instantiate(window.CardViewData.landNode);
        tmpNode.getComponent("LandNode").index = preManIndex;

        console.log(this.index);
        console.log(preManIndex);
        window.CardViewData.landArr.splice(preManIndex, 1, tmpNode.getComponent("LandNode"));
        window.CardViewData.landArr.splice(this.index, 1, window.CardViewData.manLand);
        window.CardViewData.dynamicData.landArrChange = true;

    },
    checkMoveable: function () {
        // 横向投影，纵向投影
        // 如果2边投影之和为1说明可以点击
        var modRowMan = window.CardViewData.manLand.index % window.CardViewData.rowNum;
        var modRowThis = this.index % window.CardViewData.rowNum;
        var modColMan = parseInt(window.CardViewData.manLand.index / window.CardViewData.rowNum);
        var modColThis = parseInt(this.index / window.CardViewData.rowNum);
        let result = Math.abs(modRowMan - modRowThis) + Math.abs(modColMan - modColThis);
        return result == 1;
    }
});

